﻿<vs:DialogWindow x:Class="Microsoft.Data.Entity.Design.UI.Views.Dialogs.EnumTypeDialog"
                 x:ClassModifier="internal"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
                 xmlns:ded="clr-namespace:Microsoft.Data.Entity.Design"
                 xmlns:vm="clr-namespace:Microsoft.Data.Entity.Design.UI.ViewModels"
                 xmlns:core-controls="clr-namespace:Microsoft.Data.Entity.Design.Core.Controls;assembly=Microsoft.Data.Tools.Design.XmlCore"
                 mc:Ignorable="d"
                 d:DesignWidth="450" 
                 d:DesignHeight="575"
                 MinWidth="450" 
                 MinHeight="575"
                 SizeToContent="WidthAndHeight"
                 ShowInTaskbar="False"
                 WindowStartupLocation="CenterOwner"
                 ResizeMode="CanResizeWithGrip"
                 FontFamily="{DynamicResource VsFont.EnvironmentFontFamily}"
                 FontSize="{DynamicResource VsFont.EnvironmentFontSize}"
                 BorderBrush="{DynamicResource VsBrush.ActiveBorder}" BorderThickness="0,0,1,0"
                 Background="{DynamicResource {x:Static SystemColors.ControlBrushKey }}"
                 FocusManager.FocusedElement="{Binding ElementName=txtEnumTypeName}">

    <vs:DialogWindow.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Microsoft.Data.Entity.Design;Component/Resources/EscherIcons.xaml"/>
      </ResourceDictionary.MergedDictionaries>

        <!-- Draw hint on top of external type textbox -->
      <VisualBrush x:Key="ExternalTypeHint" TileMode="None" Stretch="None" AlignmentX="Left">
        <VisualBrush.Transform>
          <TranslateTransform X="5" Y="0" />
        </VisualBrush.Transform>
        <VisualBrush.Visual>
          <Grid>
            <TextBlock FontStyle="Italic" Opacity="0.8" Text="{x:Static ded:Resources.EnumDialog_ExternalTypeHint}" />
          </Grid>
        </VisualBrush.Visual>
      </VisualBrush>

      <!-- Base style for all text-boxes -->
      <Style x:Key="BaseTextBoxStyle" TargetType="TextBox">
          <Setter Property="Validation.ErrorTemplate">
              <Setter.Value>
                  <ControlTemplate>
                    <DockPanel LastChildFill="True">
                      <AdornedElementPlaceholder Name="customAdorner"/>
                      <Image Source="{StaticResource WarningPngIcon}" Margin="3,0,3,0" VerticalAlignment="Center"
                             AutomationProperties.Name="WarningError" Stretch="None" ToolTip="{Binding ElementName=customAdorner, 
                                       Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" />
                    </DockPanel>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
          <Style.Triggers>
              <Trigger Property="Validation.HasError" Value="true">
                  <Setter Property="Background" Value="{DynamicResource VsBrush.ControlEditRequiredBackground}" />
                  <Setter Property="Foreground" Value="{DynamicResource VsBrush.ControlEditRequiredHintText}" />
                  <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
               </Trigger>
          </Style.Triggers>
      </Style>

      <!-- Style for external type name text-box -->
      <Style x:Key="ExternalTypeNameStyle" TargetType="TextBox" BasedOn="{StaticResource BaseTextBoxStyle}">
        <Style.Triggers>
          <MultiTrigger>
            <MultiTrigger.Conditions>
              <Condition Property="Text" Value="" />
              <!-- <Condition Property="IsKeyboardFocusWithin" Value="False"/> -->
            </MultiTrigger.Conditions>
            <Setter Property="Background" Value="{StaticResource ExternalTypeHint}"/>
          </MultiTrigger>
          <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="Background" Value="{DynamicResource VsBrush.ControlEditRequiredBackground}" />
            <Setter Property="Foreground" Value="{DynamicResource VsBrush.ControlEditRequiredHintText}" />
            <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
          </Trigger>
          <Trigger Property="Visibility" Value="Visible">
            <Trigger.EnterActions>
              <BeginStoryboard>
                <Storyboard>
                  <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                   From="0"
                                   To="1"
                                   Duration="0:0:1" />
                </Storyboard>
              </BeginStoryboard>
            </Trigger.EnterActions>
          </Trigger>
        </Style.Triggers>        
      </Style>

      <Style TargetType="{x:Type DataGridRow}">
        <Setter Property="ValidationErrorTemplate">
          <Setter.Value>
            <ControlTemplate>
              <DockPanel LastChildFill="True">
                <AdornedElementPlaceholder Name="customAdorner"/>
                <Image Source="{StaticResource WarningPngIcon}" Margin="0,0,0,0" VerticalAlignment="Center"
                       AutomationProperties.Name="WarningError" Stretch="None" ToolTip="{Binding ElementName=customAdorner, 
                                       Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" />
              </DockPanel>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        <Style.Triggers>
              <Trigger Property="Validation.HasError" Value="true">
                  <Setter Property="Background" Value="{DynamicResource VsBrush.ControlEditRequiredBackground}" />
                  <Setter Property="Foreground" Value="{DynamicResource VsBrush.ControlEditRequiredHintText}" />
                  <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
              </Trigger>
          </Style.Triggers>
      </Style>

      <core-controls:InverseBooleanConverter x:Key="InverseBooleanConverter" />
    </ResourceDictionary>
 </vs:DialogWindow.Resources>
    
    <Grid Margin="10,10,10,10" AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_AutomationName}">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static ded:Resources.EnumDialog_NameLabel}" 
                 VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5,5,5,2"/>

      <TextBox Grid.Column="0" Grid.Row="1" 
               Name="txtEnumTypeName" HorizontalAlignment="Left" 
               Margin="5,0,5,5" AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_NameLabel}" 
               Width="250px" TextChanged="OnTextBoxTextChanged" LostFocus="OnTextBoxLostFocus" Style="{StaticResource BaseTextBoxStyle}">
        <TextBox.Text>
          <Binding Path="Name">
            <Binding.ValidationRules>
              <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
            </Binding.ValidationRules>
          </Binding>
        </TextBox.Text>
      </TextBox>

      <TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static ded:Resources.EnumDialog_UnderlyingTypeLabel}" Margin="5,2,5,2" />

      <ComboBox Grid.Column="0" Grid.Row="3"  HorizontalAlignment="Left" Name="cmbUnderlyingType"
              Margin="5,0,5,5" Width="250px"
              ItemsSource="{Binding Path=UnderlyingTypes}"
              SelectedItem="{Binding Path=SelectedUnderlyingType,Mode=TwoWay}"
              AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_UnderlyingTypeLabel}" 
              ToolTip="{x:Static ded:Resources.PropertyWindow_Description_EnumUnderlyingType}"/>

      <DataGrid Grid.Column="0" Grid.Row="4" HorizontalAlignment="Stretch"
                Name="dgEnumTypeMembers" VerticalAlignment="Stretch" ItemsSource="{Binding Path=Members}"
                CanUserAddRows="True" CanUserDeleteRows="True" AutoGenerateColumns="False"
                HorizontalGridLinesBrush="{DynamicResource VsBrush.ThreeDFace}" VerticalGridLinesBrush="{DynamicResource VsBrush.ThreeDFace}"
                AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_AccEnumTypeMembers}"
                Margin="5,10,5,5">
        <DataGrid.RowValidationRules>
          <vm:RowDataInfoValidationRule ValidationStep="UpdatedValue" />
        </DataGrid.RowValidationRules>
        <DataGrid.Columns>
        
          <DataGridTextColumn Header="{x:Static ded:Resources.EnumDialog_EnumTypeMemberNameLabel}" CanUserSort="False" MinWidth="225" MaxWidth="325" Width="Auto">
            <DataGridTextColumn.Binding>
              <Binding Path="Name">
                <Binding.ValidationRules>
                  <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
                </Binding.ValidationRules>
              </Binding>
            </DataGridTextColumn.Binding>
          </DataGridTextColumn>

          <DataGridTextColumn Header="{x:Static ded:Resources.EnumDialog_EnumTypeMemberValueLabel}" CanUserSort="False" MinWidth="200" MaxWidth="300" Width="Auto">
            <DataGridTextColumn.Binding>
              <Binding Path="Value">
                <Binding.ValidationRules>
                  <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
                </Binding.ValidationRules>
              </Binding>
            </DataGridTextColumn.Binding>
          </DataGridTextColumn>
        </DataGrid.Columns>
      </DataGrid>

      <CheckBox Content="{x:Static ded:Resources.EnumDialog_IsFlagLabel}" Grid.Column="0" Grid.Row="5"  
                  Name="chkIsFlag" VerticalAlignment="Center" Margin="8,10,5,5" Padding="8,0,5,0" 
                  IsChecked="{Binding Path=IsFlag}" ToolTip="{x:Static ded:Resources.EnumDialog_IsFlagLabelDescription}" />

      <CheckBox Content="{x:Static ded:Resources.EnumDialog_ExternalTypeLabel}" Grid.Column="0" Grid.Row="6"
                Name="chkReferenceExternalType" VerticalAlignment="Center" Margin="8,5,5,2" Padding="8,0,5,0" IsChecked="{Binding Path=IsReferenceExternalType}"
                ToolTip="{x:Static ded:Resources.PropertyWindow_Description_EnumExternalTypeAttribute}" Click="OnRefrenceExternalTypeClick"/>
        
      <Border MaxWidth="{Binding ElementName=chkIsFlag,Path=ActualWidth}" Grid.Column="0" Grid.Row="7" Margin="0,0,0,0" BorderThickness="0,0,0,0">
        <TextBox Margin="23,5,5,5" Name="txtExternalType" HorizontalAlignment="Left" AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_ExternalTypeLabel}"
                 Width="230px" ToolTip="{x:Static ded:Resources.PropertyWindow_Description_EnumExternalTypeAttribute}"
                 Style="{StaticResource ExternalTypeNameStyle}" IsReadOnly="{Binding Path=IsChecked, ElementName=chkReferenceExternalType, Converter={StaticResource InverseBooleanConverter}}"
                 TextChanged="OnTextBoxTextChanged" LostFocus="OnTextBoxLostFocus">
            <TextBox.Text>
              <Binding Path="ExternalTypeName">
                <Binding.ValidationRules>
                  <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
                </Binding.ValidationRules>
              </Binding>
            </TextBox.Text>
        </TextBox>
      </Border>
    
      <StackPanel Grid.Column="0" Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right">
         <Button Name="btnOk"
                 Margin="5,15,5,5" MinWidth="70" IsDefault="True" 
                 Click="btnOk_Click" Content="{x:Static ded:Resources.EnumDialog_OkButtonLabel}"
                 IsEnabled="{Binding Path=IsValid}" AutomationProperties.Name="{Binding Name}"/>
        
        <Button Name="btnCancel" 
                Margin="5,15,5,5" MinWidth="70" IsCancel="True" 
                Click="btnCancel_Click" Content="{x:Static ded:Resources.EnumDialog_CancelButtonLabel}"
                AutomationProperties.Name="{Binding Name}"/>
      </StackPanel>
  </Grid>
</vs:DialogWindow>